package file

import (
	"context"
	"net/http"

	"2106A-zg6/baidu/gateway/internal/svc"
	"2106A-zg6/baidu/gateway/internal/types"
	"2106A-zg6/baidu/srv/baiduclient"

	"github.com/zeromicro/go-zero/core/logx"
)

type FileEsSerachLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFileEsSerachLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FileEsSerachLogic {
	return &FileEsSerachLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FileEsSerachLogic) FileEsSerach(req *types.FileSerach) (resp *types.Response, err error) {

	//  获取 用户ID
	//value := l.ctx.Value("custom-key")

	file, err := l.svcCtx.BaiduSrv.FileSearch(l.ctx, &baiduclient.FileSearchRequest{
		FileName: req.FileName,
		Sort:     req.Sort,
	})

	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: http.StatusAccepted,
			Data: nil,
		}, err
	}

	return &types.Response{
		Msg:  "successful",
		Code: http.StatusOK,
		Data: file,
	}, nil
}
